//定义类
class Food{
    element:HTMLElement;
    constructor(){
        this.element = document.getElementById('food')!;
    }
    //获取食物的坐标
    get X(){
        return this.element.offsetLeft;
    }
    get Y(){
        return this.element.offsetTop;
    }

    //修改食物的位置
    change(){
        //生成随机位置
        let top = Math.floor(Math.random()*30)*10;
        let left = Math.floor(Math.random()*30)*10;
        this.element.style.left = left + 'px';
        this.element.style.top = top + 'px';
    }
}
export default Food;